﻿using System;
using System.Collections.Generic;
using System.Text;
using ShootSearch.Core;

namespace ShootSearch.FileSystem
{
    public class FileSystem: IFile
    {
        protected FileSystemConfig config;
        protected int fsid = 0;

        public FileSystem()
        {
            config = new FileSystemConfig();
        }

        #region IFile Members
      

        public string FSID
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public long Length
        {
            get { throw new NotImplementedException(); }
        }

        public event FileSystemActionEventHandler FileSystemRead;

        public event FileSystemActionEventHandler FileSystemWrite;

        public event FileSystemActionEventHandler FileSystemIDChanged;

        public bool CreateOpen(string iopath, string id)
        {
            throw new NotImplementedException();
        }

        public byte[] Read(string id)
        {
            throw new NotImplementedException();
        }

        public string ReadText(string id)
        {
            throw new NotImplementedException();
        }

        public bool Write(string id, string fileName, byte[] b)
        {
            throw new NotImplementedException();
        }

        public bool Write(string id, byte[] b)
        {
            throw new NotImplementedException();
        }

        public bool WriteText(string id, string fileName, string text)
        {
            throw new NotImplementedException();
        }

        public bool WriteText(string id, string text)
        {

        }

        public void Delete(string id)
        {

        }

        public List<string> ListAllFSIDs()
        {
        }

        public List<string> ListFileNames()
        {
        }

        public void Close()
        {
            
        }

        public void Flush()
        {
            
        }

        #endregion

        #region IConfigable Members

        public ShootSearch.Core.SpiderManConfig Config
        {
            get
            {
                return config;
            }
            set
            {
                if (value is FileSystemConfig)
                {
                    config = value as FileSystemConfig;
                }
            }
        }

        #endregion
    }

    public class FileSystemConfig : SpiderManConfig
    { 
        protected string encodingName = Encoding.UTF8.HeaderName;

        public Encoding Encoding{get; protected set;}
        public string EncodingName
        {
            get { return encodingName; }
            set 
            {
                try
                {
                    Encoding encode = Encoding.GetEncoding(encodingName);
                    Encoding = encode;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);                    
                }
                
            }
        }

        public bool WriteOnly { get; set; }

        public string FSIDFormat { get; set; }

        public FileSystemConfig()
        {
            Encoding = Encoding.UTF8;
            FSIDFormat = "0000";
        }
    }
}
